package servlet;

import bean.Manager;
import dao.entity.ManagerDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "managerAddServlet", value = "/madd")
public class ManagerAddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取数据
        String mgid = (String) request.getParameter("mgid");
        String mgname = (String) request.getParameter("mgname");
        String mg_pwd = (String) request.getParameter("mg_pwd");
        String lg_time = (String) request.getParameter("lg_time");
        String status = (String) request.getParameter("status");
        String access = (String) request.getParameter("access");
        //封装数据
        Manager m = new Manager(mgid,mgname,mg_pwd,lg_time,status,access);
        //执行插入操作
        //int n = SHelper.addS(student);
        ManagerDaoImpl mdi = new ManagerDaoImpl();
        int n = mdi.addManager(m);
        if(n!=0){
            //插入成功
            request.setAttribute("n",1);
        }else {
            //插入失败
            request.setAttribute("n",0);
        }
        request.getRequestDispatcher("result.jsp").forward(request,response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }
}
